<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">
	
	<link type="text/css" href="${_js}/ueditor/themes/default/css/ueditor.css" rel="stylesheet"/>
	
    <script src="${_js}/jquery.min.js"></script>

    <!--[if lt IE 9]>
        <script src="../assets/js/ie8-responsive-file-warning.js"></script>
        <![endif]-->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

</head>


<body style="background: #F7F7F7;" class="nav-md" style="overflow:hidden">

	<div class="">
        <div class="row" id="main-row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>借款标详情</h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">

                        <form class="form-horizontal">
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-6" for="name">借款人</label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="hidden" id="borrowApplyId" value="${item.id}">
                                	<input type="hidden" id="borrowId" value="${model.id}">
                                	<input type="text" disabled="disabled" value="<#if item.userName?exists>${item.userName}</#if>" class="form-control col-md-7 col-xs-12">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-6" for="password">真实姓名
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="text" readonly="readonly" value="<#if item.realName?exists>${item.realName}</#if>" class="form-control col-md-7 col-xs-12">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">借款标题
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<input type="text" id="title" class="form-control col-md-7 col-xs-12"
                                	value="<#if model?? & model.title?exists>${model.title}</#if>">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">产品类型
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	 <select class="form-control" id="product">
                                	 	<#if productList?exists>
                                	 		<#list productList as product>
                                	 			<option value= "${product.id}" <#if (model?exists && model.productId == product.id)>selected = "selected"</#if>>${product.name}</option>
                                	 		</#list>
                                	 	</#if>
                                    </select>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">担保方
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                	<select class="form-control" id="guaranteeName">
	                                	<#if guaranteeAll?exists>
	                                		<#list guaranteeAll as guarantee>
	                                			<option value= "${guarantee}" <#if model?exists && model.guaranteeName == guarantee>selected = "selected"</#if>>${guarantee}</option>
	                                		</#list>
	                                	</#if>
                                	</select>
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">借款金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="amount"  class="form-control col-md-7 col-xs-7" 
                                   value="<#if model?? & model.amount?exists>${model.amount}
                                   		<#elseif item?? & item.amount?exists>${item.amount}</#if>"
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" 
                                   >
                                </div>
                            </div>  
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="password">借款期限(月/天)
                                </label>
                                
						        <div class="col-md-1 col-sm-3 col-xs-3" style="height:40px;line-height:40px;">
						          	月标 <input name="date_type" type="radio" value="MONTH" <#if (model?exists) && (model.dateUtil=="MONTH")>checked<#elseif item.dateUtil ?? && item.dateUtil == "MONTH">checked</#if>/>
						          	天标<input name="date_type" type="radio" value="DAY" <#if (model?exists) && (model.dateUtil=="DAY")>checked<#elseif item.dateUtil ?? && item.dateUtil == "DAY">checked</#if>/>
						        </div> 
						                                        
                                <div class="col-md-2 col-sm-3 col-xs-3">
                                	<input type="text" id="date" class="form-control col-md-7 col-xs-12" 
                                	onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                	value="<#if model?? & model.deadline?exists>${model.deadline}<#elseif item?? && item.date?exists>${item.date}</#if>">借款成功后还完贷款的期限。
                                </div>
                                
                               
                            </div>                                                                                   
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">还款方式
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <select class="form-control" id="paymentMode">
                                        <option value="">请选择还款方式</option>
                                        <option value="3" <#if model?? & model.paymentMode==3>selected="selected"</#if>>按月付息,到期还本</option>
                                        <option value="2" <#if model?? & model.paymentMode==2>selected="selected"</#if>>等额本息</option>
                                        <option value="1" <#if model?? & model.paymentMode==1>selected="selected"</#if>>一次性还款</option>
                                    </select>
                                    	按月付息还款是指贷款者借款成功后,每月还息，到期还本
                                </div>
                            </div>                        
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">年化率
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="precent" class="form-control col-md-7 col-xs-12" 
                                   value="<#if model?? & model.percent?exists>${model.percent}</#if>"
                                   >借款标的年化收益率
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">最小投标金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="min" class="form-control col-md-7 col-xs-12" 
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   value="<#if model?? & model.min?exists>${model.min}</#if>"
                                   >对投资者对一个借款标的最低投标总额的限制
                                </div>
                            </div> 
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">最大投标金额
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="max" class="form-control col-md-7 col-xs-12" 
                                    value="<#if model?? & model.max?exists>${model.max}</#if>"
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   >允许投资者对一个借款标的投标总额的限制
                                </div>
                            </div>  
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-password">有效时间(天)
                                </label>
                                <div class="col-md-3 col-sm-3 col-xs-6">
                                   <input type="text" id="expire" class="form-control col-md-7 col-xs-12" 
                                   onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                   value="<#if expireDay??>${expireDay}</#if>"
                                   >设置此次借款融资的天数。在有效期内未融资成功，自动成为过期标
                                </div>
                            </div>
                            <div class="item form-group">
						        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-single_cal">是否债权回购</label>
						        <div class="col-md-3 col-sm-3 col-xs-6" style="height:40px;line-height:40px;">
						          	否 <input name="isBuyBack" type="radio" value="N" <#if model.isBuyBack?? && model.isBuyBack == "N">checked</#if>/>
						          	是 <input name="isBuyBack" type="radio" value="Y" <#if model.isBuyBack?? && model.isBuyBack == "Y">checked</#if>/>
						        </div>
						    </div>
						    
                            <div class="item form-group">
						        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-single_cal2">设置定时显示</label>
						        <div class="col-md-3 col-sm-3 col-xs-6" style="height:40px;line-height:40px;">
						          	否 <input name="Fruit" type="radio" value="0" <#if model.timingShow?exists><#else>checked</#if>/>
						          	是 <input name="Fruit" type="radio" value="1" <#if model.timingShow?exists>checked</#if>/>
						        </div>
						    </div>
                            <div class="item form-group" style="display:none" id="timing">
						        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="re-single_cal2">定时显示时间</label>
						        <div class="col-md-3 col-sm-3 col-xs-6">
						            <input style="margin-left: 0px;" data-date-format="yyyy-mm-dd hh:ii:ss" readonly 
						            class="form-control col-md-7 col-xs-12" onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
						             id="single_cal2" type="text" value="<#if model?? && model.timingShow??>${model.timingShow?string('yyyy-MM-dd HH:mm:ss')}</#if>"/>
						        </div>
						    </div>
                        </form>
                    </div>
                </div>
            </div>
        </div> 
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                        <div class="x_title">
                            <h2>个人信息</h2>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content" id="borrow-person">
                        <input type="hidden" id="status" value="<#if model.status??>${model.status}</#if>">
                            <#if model.status!='borrow'>                          	
	                            <#if model.personalInfo??>
	                            	<#list personalList as model>
	                            		<img src="${model.path}" style="height: 200px;width: 240px;" alt="">
	                            	</#list>
	                            </#if>
	                        <#else>
	                        	<form action="/file/uploadAuthFile" enctype="multipart/form-data" id="personForm" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px;">
                            		<input type="hidden" id="borrowId" value="<#if model.id??>${model.id}</#if>">                     
                            		<input type="hidden" id="person" value="<#if model.personalInfo??>${model.personalInfo}</#if>">
                            		<#if model.personalInfo??>
										<#if  personalList?exists>
											<#list personalList as model>
												<div class="dz-preview dz-processing dz-image-preview dz-success dz-complete"> 
													<div class="dz-image">
														<img src="${model.path}" style="height:126px;width:126px;" alt="">
													</div>
													<a class="dz-remove" href="javascript:removePersonFile(${model.id})" data-dz-remove="">删除文件</a>
												</div>
											</#list>
										</#if>
									</#if>
                            	</form>
                           	</#if>
                        </div>
                    </div>
                </div>
            </div>
        </div>
       	<!--资产材料-->
       	<div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                        <div class="x_title">
                            <h2>资产材料</h2>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content" id="borrow-fund">                     
                            <#if model.status!='borrow'>                            	
	                            <#if model.capitalInfo??>
	                            	<#list capitalList as model>
	                            		<img src="${model.path}" style="height: 200px;width: 240px;" alt="">
	                            	</#list>
	                            </#if>
	                        <#else>
	                        	<form action="/file/uploadAuthFile" enctype="multipart/form-data" id="fundForm" class="dropzone" style="border: 1px solid #e5e5e5; height: 300px;">
                            		<input type="hidden" id="borrowId" value="<#if model.id??>${model.id}</#if>">                     
                            		<input type="hidden" id="fund" value="<#if model.capitalInfo??>${model.capitalInfo}</#if>">
                            		<#if model.capitalInfo??>
										<#if  capitalList?exists>
											<#list capitalList as model>
												<div class="dz-preview dz-processing dz-image-preview dz-success dz-complete"> 
													<div class="dz-image">
														<img src="${model.path}" style="height:126px;width:126px;" alt="">
													</div>
													<a class="dz-remove" href="javascript:removeFundFile(${model.id})" data-dz-remove="">删除文件</a>
												</div>
											</#list>
										</#if>
									</#if>
                            	</form>
                           	</#if>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="row">
        	<div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                	<div class="x_title">
	                    <h2>借入详情</h2>
	                     <div class="clearfix"></div>
                    </div>
                    <div style="width: 1884px; max-height: 500px; z-index: 999; overflow: scroll;">
                    	<script id="editor" type="text/plain" style="height:500px;"></script>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
        	<div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                	<div class="x_title">
	                    <h2>资产凭证</h2>
	                     <div class="clearfix"></div>
                    </div>
                    <div style="width: 1884px; max-height: 500px; z-index: 999; overflow: scroll;">
                    	<script id="editor2" type="text/plain" style="height:500px;"></script>
                    </div>	
                </div>
            </div>
        </div>
        <div class="row">
        	<div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                	<div class="x_title">
	                    <h2>贷后回访</h2>
	                     <div class="clearfix"></div>
                    </div>                  
                    <div style="width: 1884px; max-height: 500px; z-index: 999; overflow: scroll;">
                    	<script id="editor3" type="text/plain" style="height:500px;"></script>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" id="submit-line" style="margin-bottom:50px">
        	<div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-6 col-md-offset-5">
                        <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" id="btn-submit" class="btn btn-success">保存</button>
                    </div>
    			</div>
        	</div>       
		</div>
	</div>

	<div id="custom_notifications" class="custom-notifications dsp_none">
        <ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group">
        </ul>
        <div class="clearfix"></div>
        <div id="notif-group" class="tabbed_notifications"></div>
    </div>
    
   <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
    <!-- icheck -->
    <script src="${_js}/icheck/icheck.min.js"></script>
    
    <script type="text/javascript" src="${_front_js}/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${_js}/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"></script>
	<script type="text/javascript" src="${_js}/datetimepicker/bootstrap-datetimepicker.fr.js" charset="UTF-8"></script>
	
	<script src="${_js}/custom.js" type="text/javascript"></script>
	<!-- dropzone -->
    <script src="${_js}/dropzone/dropzone.js" type="text/javascript" ></script>

    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/ueditor.all.js"> </script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${_js}/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
    	$.ajaxSetup({
			headers: {'Content-Type': 'application/json;charset=UTF-8'}
		});   
		
    	var ueditor = UE.getEditor('editor');
    	$(document).ready(function () {
        		ueditor.addListener('ready', function() {
			    	ueditor.setContent('<#if (model?exists) && (model.borrowDetail?exists)>${model.borrowDetail}</#if>');
           		});
        });
    	var ueditor2 = UE.getEditor('editor2');
    	$(document).ready(function () {
        		ueditor2.addListener('ready', function() {
			    	ueditor2.setContent('<#if (model?exists) && (model.capitalVoucher?exists)>${model.capitalVoucher}</#if>');
           		});
        });
    	var ueditor3 = UE.getEditor('editor3');
    	$(document).ready(function () {
        		ueditor3.addListener('ready', function() {
			    	ueditor3.setContent('<#if (model?exists) && (model.loanVisit?exists)>${model.loanVisit}</#if>');
           		});
        });
        
        $(document).ready(function () {
	        $('.form_datetime').datetimepicker({
		        language:  'zh-CN', 
	            showMeridian: true,
	        	autoclose: true,
	        	todayBtn: true
		    });
    	});
    	
    </script>
    
    <script>
        $(function () {
            var cnt = 10; //$("#custom_notifications ul.notifications li").length + 1;
            TabbedNotification = function (options) {
                var message = "<div id='ntf" + cnt + "' class='text alert-" + options.type + "' style='display:none'><h2><i class='fa fa-bell'></i> " + options.title + "</h2><div class='close'><a href='javascript:;' class='notification_close'><i class='fa fa-close'></i></a></div><p>" + options.text + "</p></div>";

                if (document.getElementById('custom_notifications') == null) {
                    alert('doesnt exists');
                } else {
                    $('#custom_notifications ul.notifications').append("<li><a id='ntlink" + cnt + "' class='alert-" + options.type + "' href='#ntf" + cnt + "'><i class='fa fa-bell animated shake'></i></a></li>");
                    $('#custom_notifications #notif-group').append(message);
                    cnt++;
                    CustomTabs(options);
                }
            }

            CustomTabs = function (options) {
                $('.tabbed_notifications > div').hide();
                $('.tabbed_notifications > div:first-of-type').show();
                $('#custom_notifications').removeClass('dsp_none');
                $('.notifications a').click(function (e) {
                    e.preventDefault();
                    var $this = $(this),
                        tabbed_notifications = '#' + $this.parents('.notifications').data('tabbed_notifications'),
                        others = $this.closest('li').siblings().children('a'),
                        target = $this.attr('href');
                    others.removeClass('active');
                    $this.addClass('active');
                    $(tabbed_notifications).children('div').hide();
                    $(target).show();
                });
            }

            CustomTabs();

            var tabid = idname = '';
            $(document).on('click', '.notification_close', function (e) {
                idname = $(this).parent().parent().attr("id");
                tabid = idname.substr(-2);
                $('#ntf' + tabid).remove();
                $('#ntlink' + tabid).parent().remove();
                $('.notifications a').first().addClass('active');
                $('#notif-group div').first().css('display','block');
            });
        })
    </script>
        
    <script type="text/javascript">
    	<!--个人资料-->
	    $("#personForm").dropzone({
			acceptedFiles:'.jpg,.png,.jpeg,.gif,.bmp',
			addRemoveLinks:true,
			dictRemoveFile:'删除文件',
		    init: function() {
	        	this.on("complete", function(file) {
	        	   if(file!=null){
	            	   	 new TabbedNotification({
			            	title: '操作提示',
			            	text: '文件上传成功!',
			            	delay: 3e3,
			            	type: 'success'
			        	});
		        		        		
		        		var result=JSON.parse(file.xhr.response);
		   
			        	if(result.code == 0){
			        		alert("请先登录！");
							top.location.href = "/admin/login";
			        	}
			        	var arr = new Array();
			            var ids=$("#person").val();
			            if(ids.length>0){
			            	ids+= "," + result;
			            	arr = ids.split(',');
			            }else{
			            	ids=result;
			            	arr.push(ids);
			            }
			            file.fileId = result;
			            $("#person").attr("value",ids);
			            $.each(arr, function(i, n){
			            	if($("#borrow-person .dz-remove").eq(i).attr("href")== "javascript:undefined;"){
			            		$("#borrow-person .dz-remove").eq(i).attr("href","javascript:removePersonFile("+n+")");
			            	}
						});
		        	}
		        });
		    },
		    removedfile:function(file){
		    	
	    		var value = $("#person").val();	    	
	    		var arr = value.split(',');
	    		var newArr = new Array();
	    		 $.each(arr, function(i, n){
	            	if(n != file.fileId){
	            		newArr.push(n);
	            	}
				});
	    		$("#person").attr("value",newArr);
		    	$("#borrow-person .dz-remove").each(function(i,n){
		    		var temp = $(this).attr("href");
		    		var temp2 = "javascript:removePersonFile("+file.fileId+")";
		    		if($(this).attr("href") == "javascript:removePersonFile("+file.fileId+")"){
		    			$.ajax({
				            type: "POST",
				            url:"/file/delete1",
			            	headers: {'Content-Type':'application/x-www-form-urlencoded'},
			            	data:{
			            		resourceId:file.fileId
			            	},		         
				            async: false,
				            success: function(result) {
				            	alert(result.msg);
				            	if(result.code == -1){
				            		$("#borrow-person .dz-complete:eq("+i+")").remove();
				            		//alert($("#person").val());
				            	}
				            }
				        });
		    		}
		    	});
		    }
		});	
		
		function removePersonFile(fileId){
			var value = $("#person").val();
			var borrowId = $("#borrowId").val();
    		var arr = value.split(',');
    		var newArr = new Array();
    		 $.each(arr, function(i, n){
            	if(n != fileId){
            		newArr.push(n);
            	}
			});
    		$("#person").attr("value",newArr);
			$("#borrow-person .dz-remove").each(function(i,n){
	    		if($(this).attr("href") == "javascript:removePersonFile("+fileId+")"){	    		
	    			$.ajax({
			            type: "POST",
			            url:"/admin/borrow/file/delete",
			            headers: {'Content-Type':'application/x-www-form-urlencoded'},
			            data:{
				            	f:3,
				            	x:borrowId,
				            	y:fileId
				            },
			            async: false,
			            success: function(result) {
			            	alert(result.msg);
			            	if(result.code == -1){
			            		$("#borrow-person .dz-complete:eq("+i+")").remove();
			            		//alert($("#person").val());
			            	}
			            }
			        });
	    		}
	    	});
		}
		
		
	    
	    <!--资产资料-->
	    $("#fundForm").dropzone({
			acceptedFiles:'.jpg,.png,.jpeg,.gif,.bmp',
			addRemoveLinks:true,
			dictRemoveFile:'删除文件',
		    init: function() {
	        	this.on("complete", function(file) {
	        	   if(file!=null){
	            	   	 new TabbedNotification({
			            	title: '操作提示',
			            	text: '文件上传成功!',
			            	delay: 3e3,
			            	type: 'success'
			        	});
		        		        		
		        		var result=JSON.parse(file.xhr.response);
		   
			        	if(result.code == 0){
			        		alert("请先登录！");
							top.location.href = "/admin/login";
			        	}
			        	var arr = new Array();
			            var ids=$("#fund").val();
			            if(ids.length>0){
			            	ids+= "," + result;
			            	arr = ids.split(',');
			            }else{
			            	ids=result;
			            	arr.push(ids);
			            }
			            file.fileId = result;
			            $("#fund").attr("value",ids);
			            $.each(arr, function(i, n){
			            	if($("#borrow-fund .dz-remove").eq(i).attr("href")== "javascript:undefined;"){
			            		$("#borrow-fund .dz-remove").eq(i).attr("href","javascript:removeFundFile("+n+")");
			            	}
						});
		        	}
		        });
		    },
		    removedfile:function(file){
		    	
	    		var value = $("#fund").val();
	    		var arr = value.split(',');
	    		var newArr = new Array();
	    		 $.each(arr, function(i, n){
	            	if(n != file.fileId){
	            		newArr.push(n);
	            	}
				});
	    		$("#fund").attr("value",newArr);
		    	$("#borrow-fund .dz-remove").each(function(i,n){
		    		var temp = $(this).attr("href");
		    		var temp2 = "javascript:removeFundFile("+file.fileId+")";
		    		if($(this).attr("href") == "javascript:removeFundFile("+file.fileId+")"){
		    			$.ajax({
				            type: "POST",
				            url:"/file/delete1",
			            	headers: {'Content-Type':'application/x-www-form-urlencoded'},
			            	data:{
			            		resourceId:file.fileId
			            	},			         
				            async: false,
				            success: function(result) {
				            	alert(result.msg);
				            	if(result.code == -1){
				            		$("#borrow-fund .dz-complete:eq("+i+")").remove();
				            		//alert($("#fund").val());
				            	}
				            }
				        });
		    		}
		    	});
		    }
		});	
		
		function removeFundFile(fileId){
			var value = $("#fund").val();
			var borrowId = $("#borrowId").val();
    		var arr = value.split(',');
    		var newArr = new Array();
    		 $.each(arr, function(i, n){
            	if(n != fileId){
            		newArr.push(n);
            	}
			});
    		$("#fund").attr("value",newArr);
			$("#borrow-fund .dz-remove").each(function(i,n){
	    		if($(this).attr("href") == "javascript:removeFundFile("+fileId+")"){	    		
	    			$.ajax({
			            type: "POST",
			            url:"/admin/borrow/file/delete",
			            headers: {'Content-Type':'application/x-www-form-urlencoded'},
			            data:{
				            	f:4,
				            	x:borrowId,
				            	y:fileId
				            },
			            async: false,
			            success: function(result) {
			            	alert(result.msg);
			            	if(result.code == -1){
			            		$("#borrow-fund .dz-complete:eq("+i+")").remove();
			            		//alert($("#fund").val());
			            	}
			            }
			        });
	    		}
	    	});
		}
	
    $(function () {
        <!--checkbox设置单选 -->
        $(".icheckbox_flat-green .iCheck-helper").click(function(){
	    	$(".icheckbox_flat-green ").each(function(){
	    		$(this).removeClass('checked');
	    	});
	    	var input=$(this).parent().find('.isSetting').attr('data-input');
	    	if(input=='Y'){
	    		$(".hidden-item").show();
	    		$("#hidden-borrowGroup").hide();
	    		//当设置投资密码时，私有标组值清空（二者选一）
	    		$("input[name='borrowGroup']").attr("checked",false); 
	    	}else{
	    		$(".hidden-item").hide();
	    		$("#hidden-borrowGroup").show();
	    		//不设置投资密码时，清除投资密码
	    		var ePwd = document.getElementById("pwd");
	    		var eRePwd = document.getElementById("rePwd");
	    		ePwd.value ="";
	    		eRePwd.value ="";
	    	}
	    	$(this).parent().addClass('checked');
	 	})
	});
	
	 $("#btn-submit").click(function(){
	 	var borrowId = $("#borrowId").val();
        $('#descr').val($('#editor').html())
   		var applyid=$("#borrowApplyId").val();
   		var title=$.trim($("#title").val());
   		var product=$.trim($("#product").val());
   		var amount=$.trim($("#amount").val());
   		var date=$.trim($("#date").val());
   		var paymentMode=$.trim($("#paymentMode").val());
   		var percent=$.trim($("#precent").val());
   		var min=$.trim($("#min").val());
   		var max=$.trim($("#max").val());
   		var status = $.trim($("#status").val());
   		var expire=$.trim($("#expire").val());
   		var privateBorrow = "";
   		var timing  = $('input[name="Fruit"]:checked').val();
   		var date_type  = $('input[name="date_type"]:checked').val(); 
   		var guaranteeName  = $.trim($("#guaranteeName").val());//担保方
   		var personalInfo = $.trim($("#person").val());//个人信息上传图片id
   		var capitalInfo = $.trim($("#fund").val());//资产信息上传图片id
   		var borrowDetail = ueditor.getContent();//借入详情
   		var capitalVoucher = ueditor2.getContent();//资产凭证
   		var loanVisit = ueditor3.getContent();//贷后回访
   		var isBuyBack = $('input[name="isBuyBack"]:checked').val();//是否债权回购
   		if(timing == 1){
   			var timingShow = $("#single_cal2").val();
   			if(timingShow == ""){
   				new TabbedNotification({
		            	title: '操作提示',
		            	text: '定时显示时间不能为空',
		            	delay: 3e3,
		            	type: 'error'
		        	});
				return;
   			}
   		} 
   		if(title == ""){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '借款标题不能为空',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(paymentMode == ""){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '请选择还款方式',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(amount == "" || parseFloat(amount)<=0){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '借款金额为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(amount%100 != 0){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '借款金额必须为100的倍数',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(date == "" || parseInt(date)<=0){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '借款期限为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
		if(percent == ""){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '年化率不能为空',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
   		if(percent != "" && 
   			(percent.indexOf("-") != -1 || (percent.indexOf("0") == 0 && percent.indexOf(".") == -1) || !regRewardPercent(percent))){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '年化率应为整数或者小数!',
		            	delay: 3e3,
		            	type: 'error'
		        	});
        	return;
   		}
   		if(expire == "" || parseInt(expire)<=0){
   			new TabbedNotification({
		            	title: '操作提示',
		            	text: '有效天数为空或输入错误',
		            	delay: 3e3,
		            	type: 'error'
		        	});
			return;
   		}
		
		if(guaranteeName == ""){
			new TabbedNotification({
		            	title: '操作提示',
		            	text: '请输入担保方',
		            	delay: 3e3,
		            	type: 'error'
		        	});
   			return;
		}
		
		if(borrowDetail == ""){
			new TabbedNotification({
		            	title: '操作提示',
		            	text: '请输入借入详情',
		            	delay: 3e3,
		            	type: 'error'
		        	});
   			return;
		}
		if(capitalVoucher == ""){
			new TabbedNotification({
		            	title: '操作提示',
		            	text: '请输入资产凭证',
		            	delay: 3e3,
		            	type: 'error'
		        	});
   			return;
		}
		
		if(timing == 1){
			var borrow=JSON.stringify({
				id:borrowId,
	   			borrowApplyId:applyid,
	   			title:title,
	   			productId:product,
	   			amount:amount,
	   			percent:percent,
	   			deadline:date,
	   			paymentMode:paymentMode,
	   			min:min,
	   			max:max,
	   			status:status,
	   			dateUtil:date_type,
	   			expire:expire,
	   			timingShow:timingShow,	   			
	   			guaranteeName:guaranteeName,
	   			personalInfo:personalInfo,
	   			capitalInfo:capitalInfo,
	   			borrowDetail:borrowDetail,
	   			capitalVoucher:capitalVoucher,
	   			loanVisit:loanVisit,
	   			isBuyBack:isBuyBack
	   		});
		}else{
	   		var borrow=JSON.stringify({
	   			id:borrowId,
	   			borrowApplyId:applyid,
	   			title:title,
	   			productId:product,
	   			amount:amount,
	   			percent:percent,
	   			deadline:date,
	   			paymentMode:paymentMode,
	   			min:min,
	   			max:max,
	   			status:status,
	   			dateUtil:date_type,
	   			expire:expire,	   			
	   			guaranteeName:guaranteeName,
	   			personalInfo:personalInfo,
	   			capitalInfo:capitalInfo,
	   			borrowDetail:borrowDetail,
	   			capitalVoucher:capitalVoucher,
	   			loanVisit:loanVisit,
	   			isBuyBack:isBuyBack
	   		});
   		}
   		$.ajax({
            type: 'post',
            dataType: 'JSON',
            async:'false',
            headers: {'Content-type': 'application/json;charset=UTF-8'},
            url: '/admin/borrow/save',
            data:borrow,
            success: function(result){
           		 if(result.code==-1){
           		 	alert("保存成功!");
		        	window.location.href="/admin/borrow/list";         		 	
           		 }else{
           		 	if(result.code == 0){
		        		alert("请先登录！");
						top.location.href = "/admin/login";
		        	}else{
		        		alert(result.msg);
		        		return false; 
		        	}
           		 }
            },error:function(result){
            	alert("服务器异常，请稍后再试!");
            }
        });    
   }) 
   
   function regRewardPercent(rewardPercent){
		var reg =/^-?\d*(?:\.\d{0,2})?$/;
		if(reg.test(rewardPercent)){
			return true;
		}else{
			return false;
		}
   }
   $(function(){
  		$("input[name='Fruit']").click(function(){
  		    var temp = $(this).val();
  		    if(temp == 1 ){
  		    document.getElementById("timing").style.display="";
  		    }else{
  		    document.getElementById("timing").style.display="none";
  		    }
  		});
 	});
 	<#if model.timingShow?exists>
		document.getElementById("timing").style.display="";
	</#if>
    </script>
</body>
</html>